/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package workdb;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;
import oracle.jdbc.pool.OracleDataSource;
/**
 *
 * @author Андрей
 */
public class database {
    static Connection setConnection() throws SQLException{
        Locale.setDefault(Locale.ENGLISH);
        OracleDataSource ds = new OracleDataSource ( );
        ds.setDriverType("thin");
        ds.setServerName("localhost");
        ds.setPortNumber(1521);
        ds.setDatabaseName("xe");
        ds.setUser("cracker");
        ds.setPassword("cracker123");
        Connection conn = ds.getConnection( );
        return conn;
    }
    public static void delEmp(String id) throws SQLException{
        Connection conn=database.setConnection();
        PreparedStatement stat=conn.prepareStatement("delete from emp where empno=?");
        stat.setString(1, id);
        stat.executeUpdate();
        conn.commit();
        stat.close();
        conn.close();
    }
    public static String[] findEmp(String id) throws SQLException{
        Connection conn=database.setConnection();
        PreparedStatement stat=conn.prepareStatement("select * from emp where empno=?");
        stat.setString(1, id);
        ResultSet rs=stat.executeQuery();
        String [] res=new String[7];
        while(rs.next()){
          res[0]=rs.getString(2);
          res[1]=rs.getString(3);
          res[2]=rs.getString(4);
          res[3]=rs.getString(5);
          res[4]=rs.getString(6);
          res[5]=rs.getString(7);
          res[6]=rs.getString(8);
        }
        conn.commit();
        stat.close();
        conn.close();
        return res;
    }
}
